<?php
// 手动插入打卡积分菜单
$host = '127.0.0.1';
$port = 3306;
$database = 'qiandao';
$username = 'root';
$password = 'root';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 手动插入打卡积分菜单 ===\n\n";
    
    // 先删除旧的打卡积分菜单
    $pdo->exec("DELETE FROM system_menu WHERE title LIKE '%打卡%' OR title LIKE '%会员%' OR title LIKE '%礼品%' OR title LIKE '%兑换%' OR node LIKE 'checkin/%'");
    echo "✓ 已清理旧菜单\n\n";
    
    // 插入一级菜单：打卡积分
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (0, '打卡积分', '', '', '#', '', '_self', 50, 1, NOW())");
    $stmt->execute();
    $pid1 = $pdo->lastInsertId();
    echo "✓ 插入一级菜单：打卡积分 (ID:{$pid1})\n";
    
    // 插入二级菜单：门店管理
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '门店管理', '', '', '#', '', '_self', 100, 1, NOW())");
    $stmt->execute([$pid1]);
    $pid2_store = $pdo->lastInsertId();
    echo "✓ 插入二级菜单：门店管理 (ID:{$pid2_store})\n";
    
    // 插入三级菜单：门店信息管理
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '门店信息管理', 'layui-icon layui-icon-home', 'checkin/store/index', '', '', '_self', 100, 1, NOW())");
    $stmt->execute([$pid2_store]);
    echo "✓ 插入三级菜单：门店信息管理\n";
    
    // 插入二级菜单：会员管理
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '会员管理', '', '', '#', '', '_self', 90, 1, NOW())");
    $stmt->execute([$pid1]);
    $pid2_member = $pdo->lastInsertId();
    echo "✓ 插入二级菜单：会员管理 (ID:{$pid2_member})\n";
    
    // 插入三级菜单：会员列表
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '会员列表', 'layui-icon layui-icon-user', 'checkin/member/index', '', '', '_self', 100, 1, NOW())");
    $stmt->execute([$pid2_member]);
    echo "✓ 插入三级菜单：会员列表\n";
    
    // 插入二级菜单：打卡管理
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '打卡管理', '', '', '#', '', '_self', 80, 1, NOW())");
    $stmt->execute([$pid1]);
    $pid2_record = $pdo->lastInsertId();
    echo "✓ 插入二级菜单：打卡管理 (ID:{$pid2_record})\n";
    
    // 插入三级菜单：打卡记录
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '打卡记录', 'layui-icon layui-icon-time', 'checkin/record/index', '', '', '_self', 100, 1, NOW())");
    $stmt->execute([$pid2_record]);
    echo "✓ 插入三级菜单：打卡记录\n";
    
    // 插入二级菜单：礼品管理
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '礼品管理', '', '', '#', '', '_self', 70, 1, NOW())");
    $stmt->execute([$pid1]);
    $pid2_gift = $pdo->lastInsertId();
    echo "✓ 插入二级菜单：礼品管理 (ID:{$pid2_gift})\n";
    
    // 插入三级菜单：礼品列表
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '礼品列表', 'layui-icon layui-icon-gift', 'checkin/gift/index', '', '', '_self', 100, 1, NOW())");
    $stmt->execute([$pid2_gift]);
    echo "✓ 插入三级菜单：礼品列表\n";
    
    // 插入二级菜单：兑换管理
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '兑换管理', '', '', '#', '', '_self', 60, 1, NOW())");
    $stmt->execute([$pid1]);
    $pid2_exchange = $pdo->lastInsertId();
    echo "✓ 插入二级菜单：兑换管理 (ID:{$pid2_exchange})\n";
    
    // 插入三级菜单：兑换记录
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '兑换记录', 'layui-icon layui-icon-transfer', 'checkin/exchange/index', '', '', '_self', 100, 1, NOW())");
    $stmt->execute([$pid2_exchange]);
    echo "✓ 插入三级菜单：兑换记录\n";
    
    // 插入二级菜单：系统设置
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '系统设置', '', '', '#', '', '_self', 50, 1, NOW())");
    $stmt->execute([$pid1]);
    $pid2_setting = $pdo->lastInsertId();
    echo "✓ 插入二级菜单：系统设置 (ID:{$pid2_setting})\n";
    
    // 插入三级菜单：规则设置
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '规则设置', 'layui-icon layui-icon-set', 'checkin/setting/index', '', '', '_self', 100, 1, NOW())");
    $stmt->execute([$pid2_setting]);
    echo "✓ 插入三级菜单：规则设置\n";
    
    echo "\n✅ 打卡积分菜单插入成功！\n";
    echo "\n请刷新浏览器查看菜单。\n";
    
} catch (PDOException $e) {
    echo "错误: " . $e->getMessage() . "\n";
}

